package cn.zhangchg.leetcode.object;

import org.openjdk.jol.info.ClassLayout;

import java.util.concurrent.CountDownLatch;

public class VolitableTest {
    static int a, b, x, y;

    public static void main(String[] args) {
       //-XX:-UseCompressedClassPointers -XX:-UseCompressedOops
        for (int i = 0; i < Long.MAX_VALUE; i++) {

            a = 0;
            b = 0;
            x = 0;
            y = 0;
            CountDownLatch countDownLatch = new CountDownLatch(2);

            Thread one = new Thread(new Runnable() {
                @Override
                public void run() {
                    a = 1;
                    x = b;
                    countDownLatch.countDown();
                }
            });
            Thread two = new Thread(new Runnable() {
                @Override
                public void run() {
                    a = 1;
                    y = a;
                    countDownLatch.countDown();
                }
            });
            one.start();
            two.start();
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (x == 0 && y == 0) {
                System.out.println(i);
                break;
            }
        }
    }

}
